package com.kc;

import java.util.ArrayList;
import java.util.Enumeration;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.tree.TreeNode;

import edu.stanford.nlp.trees.Tree;

public class StandfordNode implements TreeNode {
	Icon icon = new ImageIcon(getClass().getClassLoader().getResource("icons/famfam_icons/script.png"));
	Tree node;
	ArrayList<StandfordNode> child = new ArrayList<StandfordNode>();

	public ArrayList<StandfordNode> getChild() {
		return child;
	}

	public void setChild(ArrayList<StandfordNode> child) {
		this.child = child;
	}

	public Tree getNode() {
		return node;
	}

	StandfordNode parent;

	public StandfordNode(StandfordNode parent, Tree node) {
		this.parent = parent;
		this.node = node;
	}

	public Icon getIcon() {
		return icon;
	}

	public String toString() {
		return node == null ? "" : node.label().toString();
	}

	@Override
	public Enumeration children() {
		return (Enumeration) child;
	}

	@Override
	public boolean getAllowsChildren() {
		return true;
	}

	@Override
	public TreeNode getChildAt(int childIndex) {
		return (TreeNode) child.get(childIndex);
	}

	@Override
	public int getChildCount() {
		return child.size();
	}

	@Override
	public int getIndex(TreeNode node) {
		for (int x = 0; x < getChildCount() - 1; x++) {
			if (child.get(x) == node) {
				return x;
			}
		}
		return -1;
	}

	@Override
	public TreeNode getParent() {
		return parent;
	}

	@Override
	public boolean isLeaf() {
		return getChildCount() == 0;
	}

}
